package newcoder;

/**
 * @Author 肖地洋
 * @Date 2022/7/12 16:55
 */
public class NC202 {
    public static void main(String[] args) {
//        public int minSubarray (int[] nums, int target) {
        int target = 9;
        int[] nums = new int[]{1,2,4,4,1,1,1};
        int sum = 0;
        int i=0,j=0,res=nums.length;
        while(j<nums.length){
            while(j<nums.length&&sum<target) sum+=nums[j++];
            while(i<nums.length&&sum-nums[i]>=target) sum-=nums[i++];
            res = Math.min(res,j-i);
            sum-=nums[i++];
        }
        System.out.println(res);
    }
}
